// PGLDataVectors.cpp: implementation of the CPGLDataVectors class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include <pgl/core/PGLDataVectors.h>
#include <pgl/core/DataRegistry.h>

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

#ifndef PGL_IMPLEMENT_VECTOR_DATA_TYPE
#define PGL_IMPLEMENT_VECTOR_DATA_TYPE( className, classType )\
className::className () {}; \
className::className (size_t n) : CPGLVector<classType> (n){}; \
className::className (const className::VectorT& v) : CPGLVector< classType > (v) {}; \
className::className (const classType* v, size_t n) : CPGLVector< classType > (v,n) {}; \
className::className (const className & v)					{	*this = v;}; \
className & className::operator = (const className & v)	{	if (this != &v) { this->CPGLVector< classType >::operator =(v); } return *this;}; \
void className ::SerializeXML(CPGLArchive& ar) \
{ \
	markup::CMarkupArchive& xml = *((markup::CMarkupArchive*)ar.GetMarkup()); \
	if(ar.IsStoring()) \
	{ \
		xml.AddChildElem(GetClassName()); \
		xml.IntoElem(); \
			xml.AddChildElemEx(_T("Values"), m_v); \
		xml.OutOfElem(); \
	} \
	else \
	{ \
		if  (!xml.FindChildElem(GetClassName())) \
				return; \
		xml.IntoElem(); \
			xml.FindGetChildData(_T("Values"), m_v); \
		xml.OutOfElem(); \
	} \
}
#endif

#ifndef PGL_IMPLEMENT_VEC_REF_DATA_TYPE
#define PGL_IMPLEMENT_VEC_REF_DATA_TYPE( className, replaceClassName )\
void className ::SerializeXML(CPGLArchive& ar) \
{ \
	replaceClassName dummy( GetV() ); \
	dummy.SerializeXML(ar); \
}
#endif

#ifndef PGL_IMPLEMENT_CARRAY_DATA_TYPE
#define PGL_IMPLEMENT_CARRAY_DATA_TYPE( className, classType )\
	className::className () {}; \
	className::className(\
		className::pointer data_,\
		size_t size_)\
		: CPGLCArray<classType>(data_,size_){}\
	className::className(className const& c_)\
	: CPGLCArray<classType>(c_){};\
	void className ::SerializeXML(CPGLArchive& ar) \
{ \
}
#endif
/*
markup::CMarkupArchive& xml = *((markup::CMarkupArchive*)ar.GetMarkup()); \
if(ar.IsStoring()) \
{ \
xml.AddChildElem(GetClassName()); \
xml.IntoElem(); \
xml.AddChildElemEx(_T("Values"), m_v); \
xml.OutOfElem(); \
} \
else \
{ \
if  (!xml.FindChildElem(GetClassName())) \
return; \
xml.IntoElem(); \
xml.FindGetChildData(_T("Values"), m_v); \
xml.OutOfElem(); \
} \
 */

PGL_REGISTER_DATA_TYPE( CPGLVectorD );
PGL_REGISTER_DATA_TYPE( CPGLVectorF );
PGL_REGISTER_DATA_TYPE( CPGLVectorB );
PGL_REGISTER_DATA_TYPE( CPGLVectorI );
PGL_REGISTER_DATA_TYPE( CPGLVectorS );
PGL_REGISTER_DATA_TYPE( CPGLVectorL );

PGL_IMPLEMENT_VECTOR_DATA_TYPE( CPGLVectorD , double);
PGL_IMPLEMENT_VECTOR_DATA_TYPE( CPGLVectorF , float);
PGL_IMPLEMENT_VECTOR_DATA_TYPE( CPGLVectorB , BYTE);
PGL_IMPLEMENT_VECTOR_DATA_TYPE( CPGLVectorI , int);
PGL_IMPLEMENT_VECTOR_DATA_TYPE( CPGLVectorS , short);
PGL_IMPLEMENT_VECTOR_DATA_TYPE( CPGLVectorL , long);

PGL_REGISTER_DATA_TYPE( CPGLVectorRefD );
PGL_REGISTER_DATA_TYPE( CPGLVectorRefF );
PGL_REGISTER_DATA_TYPE( CPGLVectorRefB );
PGL_REGISTER_DATA_TYPE( CPGLVectorRefI );
PGL_REGISTER_DATA_TYPE( CPGLVectorRefS );
PGL_REGISTER_DATA_TYPE( CPGLVectorRefL );

PGL_IMPLEMENT_VEC_REF_DATA_TYPE( CPGLVectorRefD, CPGLVectorD );
PGL_IMPLEMENT_VEC_REF_DATA_TYPE( CPGLVectorRefF, CPGLVectorF );
PGL_IMPLEMENT_VEC_REF_DATA_TYPE( CPGLVectorRefB, CPGLVectorB );
PGL_IMPLEMENT_VEC_REF_DATA_TYPE( CPGLVectorRefI, CPGLVectorI );
PGL_IMPLEMENT_VEC_REF_DATA_TYPE( CPGLVectorRefS, CPGLVectorS );
PGL_IMPLEMENT_VEC_REF_DATA_TYPE( CPGLVectorRefL, CPGLVectorL );

PGL_REGISTER_DATA_TYPE( CPGLCArrayD );
PGL_REGISTER_DATA_TYPE( CPGLCArrayF );
PGL_REGISTER_DATA_TYPE( CPGLCArrayB );
PGL_REGISTER_DATA_TYPE( CPGLCArrayI );
PGL_REGISTER_DATA_TYPE( CPGLCArrayS );
PGL_REGISTER_DATA_TYPE( CPGLCArrayL );

PGL_IMPLEMENT_CARRAY_DATA_TYPE( CPGLCArrayD, double );
PGL_IMPLEMENT_CARRAY_DATA_TYPE( CPGLCArrayF, float );
PGL_IMPLEMENT_CARRAY_DATA_TYPE( CPGLCArrayB, BYTE );
PGL_IMPLEMENT_CARRAY_DATA_TYPE( CPGLCArrayI, int );
PGL_IMPLEMENT_CARRAY_DATA_TYPE( CPGLCArrayS, short );
PGL_IMPLEMENT_CARRAY_DATA_TYPE( CPGLCArrayL, long );

//////////////////////////////////////////////////////////////////////////////:
// Tweak for bug 2844
#define _MFC_7_MSCP1_2844
#ifdef _MFC_7_MSCP1_2844
namespace pgl
{
	namespace implement
	{
		template <typename T, class VT>
		void ImplementVector()
		{
			size_t n=5;
			T t=1;
			T ar[2]={0, 1};
			float f=0;

			VT v;
			VT v2(n);
			const VT v3(v2);
			VT v4=v2;
			VT v5(ar,2);

			const VT::VectorT& vv=v2.GetV();
			VT::VectorT& vv2=v2.GetV();
			v4.SetV(vv);

			v2.size();
			v4.clear();
			v2.resize(5);

			v2[0]=t;
			v2.at(1)=t;
			f=v3[0];
			f=v3.at(0);
			v2.at(0)=t;
		}

		template <typename T, class VT>
		void ImplementVectorRef()
		{
			size_t i,n=5;
			T t=1;
			T ar[2]={0, 1};
			float f=0;
			VT::VectorT vt(2);
			for (i=0;i<vt.size();++i)

			VT v;
			VT v2(vt);
			const VT v3(&vt);
			VT v4=v2;
			VT v5(v2);

			const VT::VectorT& vv=v2.GetV();
			v4.SetV(vt);

			v2.size();
			v4.clear();

			f=v3[0];
			f=v3.at(0);

			vt.at(0)=t;
		}

		class CImplementVectors
		{
		public:
			CImplementVectors()
			{
				ImplementVector<float, CPGLVectorF>();
				ImplementVector<double, CPGLVectorD>();
				ImplementVector<int, CPGLVectorI>();
				ImplementVector<BYTE, CPGLVectorB>();
				ImplementVector<short, CPGLVectorS>();
				ImplementVector<long, CPGLVectorL>();

				ImplementVectorRef<float, CPGLVectorRefF>();
				ImplementVectorRef<double, CPGLVectorRefD>();
				ImplementVectorRef<int, CPGLVectorRefI>();
				ImplementVectorRef<BYTE, CPGLVectorRefB>();
				ImplementVectorRef<short, CPGLVectorRefS>();
				ImplementVectorRef<long, CPGLVectorRefL>();
			}
		};

		static CImplementVectors staticImplVector;
	}
}
#endif